home *** CD-ROM | disk | FTP | other *** search
-
- #ifndef ode_h_IS_INCLUDED
- #define ode_h_IS_INCLUDED
-
- #include <ArraysSimple.h> // defines class Vec(real)
-
- class ODESolverUDC; // forward declaration
- class ODESolver
- {
- protected:
- Vec(real) scratch1; // scratch vector needed by all algorithms
- ODESolverUDC& eqdef; // base class reference for user defined function
- void init();
- public:
- ODESolver (ODESolverUDC& eqdef); // construct object
- virtual void advance (Vec(real)& y, real& t, real& dt) =0; // one time step
- };
-
- class ODESolverUDC
- {
- public:
- virtual void equation (Vec(real)& f, const Vec(real)& y, real t) =0; //def. f
- virtual int size () =0;
- virtual void scan (Is is) =0; // read parameters needed in equation
- virtual void print (Os os) =0; // write the equation being solved
- };
-
- // solution algorithms:
- class ForwardEulerODE : public ODESolver
- {
- public:
- ForwardEulerODE (ODESolverUDC& eqdef);
- virtual void advance (Vec(real)& y, real& t, real& dt);
- };
-
- class RungeKutta4ODE : public ODESolver
- {
- Vec(real) scratch2, scratch3;
- public:
- RungeKutta4ODE (ODESolverUDC& eqdef);
- virtual void advance (Vec(real)& y, real& t, real& dt);
- };
-
- // user defined function:
- class Oscillator : public ODESolverUDC
- {
- real c1,c2,c3,c4,omega;
- public:
- Oscillator () {} // empty constructor
- virtual void equation (Vec(real)& f, const Vec(real)& y, real t);
- virtual int size () { return 2; }
- virtual void scan (Is is); // read c1,c2,c3,c4,omega from the screen
- virtual void print (Os); // write the equation being solved
- };
- #endif
-